package com.example.edu.Mapper;

import com.example.edu.Dto.ChatMessageDto;
import com.example.edu.Dto.CreateCourseAIDto;
import com.example.edu.Entity.Chapter;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ChapterMapper {
    void addChapters(@Param("chapters") List<CreateCourseAIDto> chapters, @Param("course_id") int course_id);

    @Insert("insert into chapter(chapter_name, course_id) VALUES (#{chapter.chapter_name}, #{chapter.course_id})")
    void addChapter(@Param("chapter") Chapter chapter);

    @Select("select chapter_name from chapter where chapter_id = #{id}")
    Chapter getChapter(@Param("id") int chapter_id);

    @Select("select chapter_id,chapter_name from chapter where course_id = #{course_id} order by chapter_id limit #{count} offset #{start}")
    List<Chapter> getChapters(@Param("course_id") int course_id,@Param("start") int start,@Param("count") int count);

    @Select("select chapter_name from chapter where course_id = #{course_id} order by chapter_id")
    List<String> getChapters2(@Param("course_id") int course_id);

    @Select("select count(*) from chapter where course_id = #{course_id}")
    int getChapterNum(@Param("course_id") int course_id);

    @Select("select course_id,course_name,chapter_name from course_chapter where chapter_id = #{chapter_id}")
    ChatMessageDto getMessageByChapterId(@Param("chapter_id") int chapter_id);

    @Delete("delete from chapter where chapter_id = #{chapter_id}")
    void deleteChapter(@Param("chapter_id") int chapter_id);

    @Update("update chapter set chapter_name = #{chapter.chapter_name} where chapter_id = #{chapter.chapter_id}")
    void updateChapter(@Param("chapter") Chapter chapter);
}
